package com.zygh.policeasset.mapper;

import com.zygh.policeasset.pojo.RepairAcceptDetail;
import com.zygh.policeasset.pojo.vo.RepairAcceptDetailVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface RepairAcceptDetailMapper {

    @Insert({"<script>" +
            "insert into repair_accept_detail (daily_maintenance_small_classification_id," +
            "kind,total,amount_money,repair_accept_id) " +
            "values " +
            "<foreach collection =\"repairAcceptDetailList\" item=\"RepairAcceptDetail\" separator =\",\"> " +
            " (#{RepairAcceptDetail.dailyMaintenanceSmallClassificationId}, #{RepairAcceptDetail.kind},#{RepairAcceptDetail.total}" +
            ",#{RepairAcceptDetail.amountMoney},#{RepairAcceptDetail.repairAcceptId}) " +
            "</foreach>" +
            "</script>"})
    Integer add(@Param("repairAcceptDetailList")List<RepairAcceptDetail> repairAcceptDetailList);

    @Delete("delete from repair_accept_detail where repair_accept_id = #{repairAcceptId} ")
    Integer deleteByRepairAcceptId(@Param("repairAcceptId") Integer repairAcceptId);

    @Results(id = "map", value = {
            @Result(property = "repairTypeId", column = "repair_type_id"),
            @Result(property = "amountMoney", column = "amount_money"),
            @Result(property = "repairAcceptId", column = "repair_accept_id")})
    @Select("select rad.*,dmsc.name as dailyMaintenanceSmallClassificationName," +
            "dmbc.name as dailyMaintenanceBigClassificationName,dmsc.models as models," +
            "dmsc.measurement as measurement,dmsc.price,dmsc.id as dailyMaintenanceSmallClassificationId " +
            "from repair_accept_detail rad " +
            "left join daily_maintenance_small_classification dmsc on rad.daily_maintenance_small_classification_id = dmsc.id "+
            "left join daily_maintenance_big_classification dmbc on dmsc.big_id = dmbc.id "+
          /*  "left join repair_type rt on rad.repair_type_id = rt.id " +*/
            "where repair_accept_id = #{repairAcceptId}")
    List<RepairAcceptDetailVO> findallByRepairAcceptId(Integer repairAcceptId);

    @Select("select id from repair_accept_detail where repair_accept_id = #{repairAcceptId}")
    List<Integer> findIdsByRepairAcceptId(Integer repairAcceptId);
}